package com.tianyi.domain.services;


import com.tianyi.domain.entity.MyUserEntity;
import com.tianyi.domain.repository.IMyUserRepository;
import com.tianyi.exception.ApplicationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyUserSerice implements IMyUserService{
    @Autowired
    IMyUserRepository myUserRepository;

    public MyUserEntity insertMyUser(MyUserEntity myUserEntity) throws ApplicationException {
        if(myUserRepository.find(myUserEntity.getUserName()).size() > 0){
            throw new ApplicationException(400,"重复数据");
        }
        return myUserRepository.save(myUserEntity);
    }

    /**
     * @param userName
     * @return
     */
    @Override
    public List<MyUserEntity> find(String userName) {
       return myUserRepository.find(userName);
    }
}
